home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tpmemo.zip / TPMEMO.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  7KB  |  166 lines

  1. ;******************************************************
  2. ;                  TPMEMO.ASM 1.00
  3. ;               By TurboPower Software
  4. ;******************************************************
  5.  
  6.         INCLUDE TPCOMMON.ASM
  7.  
  8. ;****************************************************** Data
  9.  
  10. DATA    SEGMENT BYTE PUBLIC
  11.  
  12.         ;Pascal variables
  13.  
  14.         EXTRN   CheckSnow : BYTE                ;If true, check for retrace
  15.         EXTRN   VideoSegment : WORD             ;Segment of Video Memory
  16.         EXTRN   ScreenWidth : BYTE              ;Current width of display
  17.  
  18. DATA    ENDS
  19.  
  20. ;****************************************************** Code
  21.  
  22. CODE    SEGMENT BYTE PUBLIC
  23.  
  24.         ASSUME  CS:CODE, DS:DATA
  25.  
  26.         PUBLIC  FastWriteCtrl, Scan
  27.  
  28. ;****************************************************** CalcOffset
  29.  
  30. ;calculate Offset in video memory.
  31. ;On entry, AX has Row, DI has Column
  32. ;On exit, CX and ES have VideoSegment, DI has offset,
  33. ; and DL = 1 if snow checking is needed
  34.  
  35. CalcOffset      PROC NEAR
  36.  
  37.         DEC     AX                      ;Row to 0..24 range
  38.         MOV     CX, WP ScreenWidth      ;CX = Rows per column
  39.         MUL     CX                      ;AX = Row * VirtualWidth
  40.         DEC     DI                      ;Column to 0..79 range
  41.         ADD     DI,AX                   ;DI = (Row * VirtualWidth) + Col
  42.         SHL     DI,1                    ;Account for attribute bytes
  43.         MOV     CX,VideoSegment         ;CX = VideoSegment
  44.         MOV     ES,CX                   ;ES:DI points to VideoSegment:Row,Col
  45.         CLD                             ;Set direction to forward
  46.         MOV     DL,CheckSnow            ;Get snow check into DL
  47.         CMP     DL,True                 ;Is it set?
  48.         JNE     CalcExit                ;Exit if not
  49.         CMP     CH,0B8h                 ;Writing to CGA memory?
  50.         JE      CalcExit                ;Exit if so
  51.         SetZero DL                      ;Otherwise turn snow checking off
  52. CalcExit:
  53.         RET                             ;Return
  54.  
  55. CalcOffset      ENDP
  56.  
  57. ;****************************************************** FastWriteCtrl
  58.  
  59. ;procedure FastWriteCtrl(St : String; Row, Col, Attr, Ctrl : Byte);
  60. ;Write St at Row,Col in Attr (video attribute) without snow. Ctrl characters
  61. ;displayed in Ctrl as upper-case letters
  62.  
  63. FWCtrl          EQU     BYTE PTR SS:[BX+4]
  64. FWAttr          EQU     BYTE PTR SS:[BX+6]
  65. FWCol           EQU     BYTE PTR SS:[BX+8]
  66. FWRow           EQU     BYTE PTR SS:[BX+10]
  67. FWSt            EQU     DWORD PTR SS:[BX+12]
  68.  
  69. FastWriteCtrl   PROC FAR
  70.  
  71.         StackFrame                      ;Set up stack frame
  72.         PUSH    DS                      ;Save DS
  73.         PUSH    BP                      ;Save BP
  74.         SetZero AH                      ;AH = 0
  75.         MOV     AL,FWRow                ;AX = Row
  76.         SetZero CH                      ;CH = 0
  77.         MOV     CL,FWCol                ;CX = Column
  78.         MOV     DI,CX                   ;DI = Column
  79.         CALL    CalcOffset              ;Call routine to calculate offset
  80.         GetDSPtr        FWSt            ;DS:SI points to St[0]
  81.         SetZero CX                      ;CX = 0
  82.         LODSB                           ;AL = Length(St); DS:SI -> St[1]
  83.         MOV     CL,AL                   ;CX = Length
  84.         JCXZ    FWExit                  ;If string empty, exit
  85.         MOV     AH,FWAttr               ;AH = Attr
  86.         MOV     BL,FWCtrl               ;BL = Ctrl
  87.         MOV     BH,AH                   ;BH = Attr
  88.         SHR     DL,1                    ;If snow checking is off...
  89.         JNC     FWNoWait                ; use FWNoWait routine
  90.         MOV     DX,03DAh                ;Point DX to CGA status port
  91. FWGetNext:
  92.         MOV     AH,BH                   ;Assume regular attribute
  93.         LODSB                           ;Load next character into AL
  94.         CMP     AL,' '                  ;Is it a ctrl character?
  95.         JAE     FWnotCtrl               ;If not, continue
  96.         MOV     AH,BL                   ;Else use Ctrl attribute
  97.         ADD     AL,64                   ;Convert ^A to A, etc.
  98. FWnotCtrl:
  99.         MOV     BP,AX                   ;Store video word in BX
  100.         WaitForRetrace                  ;Wait for an opportunity to write
  101.         WordToCGA       BP              ;Move the word
  102.         LOOP    FWGetNext               ;Get next character
  103.         JMP     SHORT FWExit            ;Done
  104. FWNoWait:
  105.         MOV     DX,4020h                ;DH = 64, DL = ' '
  106. FWNoWaitAgain:
  107.         MOV     AH,BH                   ;Assume regular attribute
  108.         LODSB                           ;Load next character into AL
  109.         CMP     AL,DL                   ;Is it a ctrl character?
  110.         JAE     FWnotCtrl2              ;If not, continue
  111.         MOV     AH,BL                   ;Else use Ctrl attribute
  112.         ADD     AL,DH                   ;Convert ^A to A, etc.
  113. FWnotCtrl2:
  114.         STOSW                           ;Move video word into place
  115.         LOOP    FWNoWaitAgain           ;Get next character
  116. FWExit:
  117.         POP     BP                      ;Restore BP
  118.         POP     DS                      ;Restore DS
  119.         RET     12                      ;Remove parameters and return
  120.  
  121. FastWriteCtrl   ENDP
  122.  
  123. ;****************************************************** Scan
  124.  
  125. ;function Scan(Limit : Integer; Ch : Char; T : Pointer) : Integer;
  126. ;Scan limit chars for char, ch not found if rslt=limit
  127.  
  128. ScT     EQU     DWORD PTR [BP+6]
  129. ScCh    EQU     BYTE PTR [BP+10]
  130. ScLimit EQU     WORD PTR [BP+12]
  131.  
  132. Scan    PROC FAR
  133.  
  134.         PUSH    BP                      ;Save BP
  135.         MOV     BP,SP                   ;Set up stack frame
  136.         CLD                             ;assume forward
  137.         MOV     AL,ScCh                 ;char to search for
  138.         MOV     CX,ScLimit              ;bytes to search
  139.         OR      CX,CX                   ;check sign
  140.         PUSHF                           ;save flags
  141.         JNS     X1
  142.         NEG     CX                      ;make positive
  143.         STD                             ;but search in reverse
  144. X1:
  145.         MOV     DX,CX                   ;save full count
  146.         LES     DI,ScT                  ;ptr to start
  147.         REPNE   SCASB                   ;search
  148.         JNE     X2
  149.         INC     CX                      ;found a match
  150. X2:
  151.         SUB     DX,CX                   ;find count to match
  152.         MOV     AX,DX                   ;ready for return
  153.         POPF
  154.         JNS     X3
  155.         NEG     AX                      ;make negative if reverse
  156. X3:
  157.         MOV     SP,BP                   ;Restore SP
  158.         POP     BP                      ;Restore BP
  159.         RET     8                       ;Remove parameters and return
  160.  
  161. Scan    ENDP
  162.  
  163. CODE    ENDS
  164.  
  165.         END
  166.